package com.evil.application.listener;

import com.alibaba.fastjson.JSON;
import com.evil.application.pojo.dto.mq.RefreshESOrderMQReqDTO;
import com.evil.application.service.ApplicationOrderDataService;
import com.evil.common.rocketmq.constant.MQConstant;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 刷新搜索引擎订单 队列消费着
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@Component
@AllArgsConstructor
@RocketMQMessageListener(
        topic = MQConstant.REFRESH_ES_ORDER_MQ_KEY,
        consumerGroup = MQConstant.REFRESH_ES_ORDER_CONSUMER_GROUP
)
public class RefreshESOrderRocketMqConsumer implements RocketMQListener<RefreshESOrderMQReqDTO> {

    private final ApplicationOrderDataService applicationOrderDataService;

    @Override
    public void onMessage(RefreshESOrderMQReqDTO refreshESOrderMQReqDTO) {
        log.info("Receive refresh elasticsearch order message：" + JSON.toJSONString(refreshESOrderMQReqDTO));
        applicationOrderDataService.refreshEsOrderId(refreshESOrderMQReqDTO.getOrderId());
    }
}
